#json !/usr/bin/env python
#-*- coding:utf-8 -*-
import os
import sys
import datetime
reload(sys) 
sys.setdefaultencoding('utf8')
import time
import MySQLdb
sys.path.insert(0,'/home/liuyue/svn/wan/')
sys.path.insert(0,'/opt/web/')
sys.path.insert(0,'/opt/wanalytics/')
from Tools import connectMySQL
from datetime import date
from datetime import timedelta

def Total():
    
    #_datesql = " "
    #数据库连接
    try:
        db = connectMySQL.connMySQL("stat")
    except MySQLdb.Error, e:
        resultStr = '{"status": "failed", "code": "4001", "str": "connect database failed"}'
        return resultStr
    db.autocommit(True)
    c = db.cursor()
    
    
    sql = " SELECT date FROM `stat_oper_board` where  date >= 20120918 and date <= 20121018 group by date  " 
    c.execute(sql)  
    result = c.fetchall()
                
    for x in result:
        sql = " insert into `stat_oper_board` (`date`,`app_id`) values ('%s','%s') " % (x[0],26)
        c.execute(sql)
        sql = " insert into `stat_oper_board` (`date`,`app_id`) values ('%s','%s') " % (x[0],27)
        c.execute(sql)
        sql = " insert into `stat_oper_board` (`date`,`app_id`) values ('%s','%s') " % (x[0],28)
        c.execute(sql)
        sql = " insert into `stat_oper_board` (`date`,`app_id`) values ('%s','%s') " % (x[0],29)
        c.execute(sql)
        sql = " insert into `stat_oper_board` (`date`,`app_id`) values ('%s','%s') " % (x[0],30)
        c.execute(sql)

                
      
    
    c.close()
    db.close()
    

if __name__ == '__main__':
    cmd = ''
    if len(sys.argv) == 2:
        cmd = sys.argv[1]

    if cmd == 'total':
        print "Total()"
        Total()
        print "Done !"
    else:
        print "Nothing Happen!"
